package com.park.web.Interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class apiInterceptor implements HandlerInterceptor {

    private static final Logger log = LoggerFactory.getLogger(apiInterceptor.class);
    private static final String initVector = "0000000000000000"; // 16 bytes IV
    private static final int signatureLength = 40;
    private static final int tokenLength = 16;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {

        log.info("---------------------【WebApi】拦截器----------------------------");
//        String JsonData = httpServletRequest.getParameter("JsonData");
//        if ("".equals(JsonData) || null == JsonData)
//            return false;
//        else {
//            BaseJWTMap att = new BaseJWTMap();
//            String version = JsonData.substring(0, 1);
//            String messageType = JsonData.substring(1, 2);
//            String token = JsonData.substring(2, tokenLength + 1 + 1);
//            String payload = JsonData.substring(1 + 1 + tokenLength, JsonData.length() - signatureLength);
//            att.setVersion(version);
//            att.setMsgtype(messageType);
//            att.setToken(token);
//            att.setPayload(payload);
//            keyAttachService ikeyAttachService = SpringContextUtils.getBean(keyAttachService.class);
//            keyAttach entity = ikeyAttachService.selectByToken(att.getToken());
//            if (null == entity)
//                return false;
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }

}
